#!/bin/sh /etc/rc.common

START=99

EXTRA_COMMANDS=" nowdo redo"
EXTRA_HELP="
            nowdo                                           Do speed test at once
            redo                                            redo speed test"

SPEEDTESTD_BIN="/usr/sbin/speedtestd"
SPEEDTESTD_PID="/var/run/speedtestd.pid"
start() {
	$SPEEDTESTD_BIN
}

stop() {
	[ -n "`ps | grep $SPEEDTESTD_BIN`" -a -f "$SPEEDTESTD_PID" ] && {
		local pid=$(cat $SPEEDTESTD_PID)
		[ -n "$pid" ] && kill $pid
	}
}

nowdo() {
	stop
	$SPEEDTESTD_BIN "now"
}

redo() {
	stop
	
	uci set speedtest.result.downband="0"
	uci set speedtest.result.upband="0"
	
	uci set speedtest.do.lastdownband="0"
	uci set speedtest.do.lastupband="0"
	uci set speedtest.do.times="0"
	uci commit speedtest
	$SPEEDTESTD_BIN
}

restart() {
	stop
	start
}

